package com.cnbm.wcsbasic.protocol.netty.modbus.entity;


import com.cnbm.wcsbasic.protocol.netty.io.common.Package;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2024-04-23 9:23
 */

public class WriteResponseFrame {
    private MBAP mbap;
    //功能码 1
    private byte functionCode;
    //寄存器起始地址 2
    private byte[] address;
    //寄存器数量 2
    private byte[] unitNum;
    private ResponseRes responseRes;

    public WriteResponseFrame(Package aPackage) {
        byte[] allBytes = aPackage.getBody();
        byte[] mbapBytes = new byte[]{allBytes[0],allBytes[1],allBytes[2],allBytes[3],allBytes[4],allBytes[5],allBytes[6]};
        this.mbap = new MBAP(mbapBytes);

        //功能码
        this.functionCode = allBytes[7];
        this.responseRes = new ResponseRes(this.functionCode);
        //开始读的数据的地址。从00 00开始读数据  寄存器起始地址
        this.address = new byte[]{allBytes[8],allBytes[9]};
        //寄存器数 2个字节
        this.unitNum = new byte[]{allBytes[10],allBytes[11]};


    }

    public byte getFunctionCode(){
        return functionCode;
    }

    public byte[] getAddress(){
        return address;
    }

    public byte[] getUnitNum(){
        return unitNum;
    }

    public ResponseRes getResponseRes() {
        return responseRes;
    }
}
